package fan.project3_pksystem.Module;

import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class OnLinePlayers {
//    在线玩家列表
    ConcurrentHashMap<Integer, WebSocketSession> hubOnlinePlayers = new ConcurrentHashMap<>();
    ConcurrentHashMap<Integer, WebSocketSession> GameOnlinePlayers = new ConcurrentHashMap<>();
//    玩家上线
    public void addHubOl(int UserId ,WebSocketSession session) {
        hubOnlinePlayers.put(UserId, session);
    }
//    玩家下线
    public void removeHubOl(int UserId) {
        hubOnlinePlayers.remove(UserId);
    }

    public WebSocketSession getHubOl(int UserId) {
        return hubOnlinePlayers.get(UserId);
    }
    public void addGameOl(int UserId ,WebSocketSession session) {
        GameOnlinePlayers.put(UserId, session);
    }
    public void removeGameOl(int UserId) {
        GameOnlinePlayers.remove(UserId);
    }
    public WebSocketSession getGameOl(int UserId) {
        return GameOnlinePlayers.get(UserId);
    }


}
